package com.znh.entity;

import com.znh.enums.PieceActionEnum;
import com.znh.enums.PieceInitLocationEnum;
import com.znh.enums.PiecePlayerEnum;

import java.awt.*;

/**
 * @version 1.0
 * @Author znh
 * @Date 2024/5/24 下午3:28
 * @注释 车类
 */
public class Che extends Piece {
    public Che(){}

    public Che(int id, Point point, PiecePlayerEnum player, PieceInitLocationEnum initLocation) {
        super(id, "che", point, player, initLocation, new StringBuilder().append("images/che")
                .append(player == PiecePlayerEnum.RED ? "0" : "1").append(".png").toString());
    }

    @Override
    public boolean isMove(Point tp) {
        PieceActionEnum action = action(tp);
        //是否走直线、当前位置到目标位置之间是否有棋子
        return (action == PieceActionEnum.LINEX && countRoutePiece(tp, PieceActionEnum.LINEX) == 0)
                || (action == PieceActionEnum.LINEY && countRoutePiece(tp, PieceActionEnum.LINEY) == 0);


    }

    @Override
    public boolean simulateMove(Point tp) {
        return isMove(tp) && super.simulateMove(tp);
    }
}
